/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gride.project;

import java.io.File;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
 *
 * @author lukasz
 */
public class GrideLibrary
{

    // <editor-fold defaultstate="expanded" desc="Members">
    
    private File file;
    
    // </editor-fold>
    
    
    // <editor-fold defaultstate="expanded" desc="Constructors">
    
    /**
     *
     * @param file
     */
    public GrideLibrary(File file)
    {
        this.file = file;
    }

    /**
     * 
     * @param node
     * @return
     */
    public static GrideLibrary loadLibrary(Element node)
    {
        NodeList nodes = node.getElementsByTagName("LibFile");
        return new GrideLibrary(new File(nodes.item(0).getTextContent()));
    }
    
    // </editor-fold>
    
    
    
    // <editor-fold defaultstate="expanded" desc="Public Methods">
    
    /**
     *
     * @return
     */
    public String getName()
    {
        return file.getName();
    }
    
    /**
     *
     * @return
     */
    public File getFile()
    {
        return file;
    }

    /**
     *
     * @return
     */
    public String getXML()
    {
        StringBuilder xml = new StringBuilder();

        xml.append("<Library>\n");
        xml.append("\t<LibFile>" + file.getAbsolutePath() + "</LibFile>\n");
        xml.append("</Library>");

        return xml.toString();
    }
    
    // </editor-fold>

}
